package com.nidu.demo.role.executor.query;

import com.alibaba.cola.dto.PageResponse;
import com.nidu.demo.role.convertor.RoleConvertor;
import com.nidu.demo.role.convertor.RoleCriteriaConvertor;
import com.nidu.demo.role.dto.RoleCO;
import com.nidu.demo.role.dto.RolePageQry;
import com.nidu.demo.role.gateway.RoleGateway;
import com.nidu.demo.role.model.Role;
import com.nidu.demo.role.model.RoleCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 角色分页查询执行器
 *
 * @author auto
 */
@Component
@RequiredArgsConstructor
public class RolePageQryExe {

    private final RoleGateway gateway;

    private final RoleConvertor convertor;

    private final RoleCriteriaConvertor criteriaConvertor;

    public PageResponse<RoleCO> execute(RolePageQry qry) {
        RoleCriteria criteria = criteriaConvertor.toDataObject(qry);
        PageResponse<Role> page = gateway.pageByCondition(criteria);
        List<RoleCO> roleCOS = convertor.toClientObjects(page.getData());
        return PageResponse.of(roleCOS, page.getTotalCount(), page.getPageSize(), page.getPageIndex());
    }
}